#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int MOD = 998244353;

void solve() {
	int n, m, d;
	cin >> n >> m >> d;
	vector<string> vec(n);
	for(int i = 0; i < n; i++) {
		cin >> vec[i];
	}
	vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(2)));
	for(int i = n - 1; i >= 0; i--) {
		vector<int> pre1(m + 1);
		for(int j = 0; j < m; j++) pre1[j + 1] = (pre1[j] + dp[i + 1][j][0] + dp[i + 1][j][1]) % MOD;
		for(int j = 0; j < m; j++) {
			if(vec[i][j] == '#') continue;
			int x = sqrt(d * d - 1);
            if(i == n - 1) dp[i][j][0] = 1;
			else (dp[i][j][0] = (pre1[min(m, j + 1 + x)] - pre1[max<int>(0, j - x)])) %= MOD;
		}
		for(int j = 0; j < m; j++) pre1[j + 1] = (pre1[j] + dp[i][j][0]) % MOD;
		for(int j = 0; j < m; j++) {
			if(vec[i][j] == '#') continue;
			int x = d;
			int t = (pre1[min(m, j + 1 + x)] - pre1[max<int>(0, j - x)]) - dp[i][j][0];
			(dp[i][j][1] = t) %= MOD;
		}
	}
	int ans = 0;
	for(int i = 0; i < m; i++) {
		ans = (ans + dp[0][i][0] + dp[0][i][1]) % MOD;
	}
	cout << ans << endl;
}

signed main() {
	int t = 1;
	cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

